<?php
/**
 * DocumentationView
 *
 * @version    1.0
 * @package    samples
 * @subpackage tutor
 * @author     Pablo Dall'Oglio
 * @copyright  Copyright (c) 2006-2011 Adianti Solutions Ltd. (http://www.adianti.com.br)
 * @license    http://www.adianti.com.br/framework-license
 */
class DocumentationView extends TPage
{
    private $label;
    private $source;
    
    public function __construct()
    {
        // parent classs constructor
        parent::__construct();
        
        // label to present the docs
        $this->label = new TText('name');
        $this->label->setSize(690, 130);
        
        // notebook to put the scroll inside
        $note   = new TNotebook(700, 150);
        $note->appendPage('Explanation', $this->label);
        
        // scroll to put the source inside
        $scroll2 = new TScroll;
        $scroll2->setSize(700, 250);
        $this->source = new TSourceCode;
        $scroll2->add($this->source);
        
        // create a table to organize the layout
        $page = new TTable;
        $row1=$page->addRow();
        $row2=$page->addRow();
        $row1->addCell($note);
        $row2->addCell($scroll2);
        parent::add($page);
    }
    
    /**
     * Method onHelp
     * Shows the source code for this sample, along with an explanation
     */
    function onHelp($param)
    {
        $folder    = 'app/control';
        $classname = $param['classname'];
        foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folder),
                                               RecursiveIteratorIterator::SELF_FIRST) as $entry)
        {
            if (is_dir($entry))
            {
                if (file_exists("{$entry}/{$classname}.class.php"))
                {
                    $resource = str_replace('app/control', 'app/resources', "{$entry}/{$classname}.txt");
                    
                    if (file_exists($resource))
                    {
                        $this->label->setValue(file_get_contents($resource));
                    }
                    else
                    {
                        $this->label->setValue('This is the source-code for this sample.');
                    }
                    $this->source->loadFile("{$entry}/{$classname}.class.php");
                }
            }
        }
    }
}
?>